<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>new的作用</title>
  </head>
  <body>
    <script>

      // 使用new
      //   function Student(obj) {
      //     // this={};
      //     this.name = obj.name;
      //     this.score = obj.score;
      //     this.garde = obj.garde;
      //     // return this;
      //   }
      //   var stu1 = new Student({ name: "小明", score: 95, garde: 6 });
      //   console.log(stu1);

      // 没有new，直接调⽤构造函数
      function Student(obj) {
        this.name = obj.name;
        this.score = obj.score;
        this.grade = obj.grade;
        console.log(this);
      }
      
      var stu1 = Student({
        name: "Jack",
        score: 88,
        grade: 3,
      });

      console.log(stu1);
      // 1.把对象返回回来
      // 2.把构造函数的this指向了要返回的对象
    </script>
  </body>
</html>
